<html>
<head>
<meta charset="UTF-8">
<title>流程实例信息列表</title>
<link id="easyuiTheme" href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
<link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
<script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
<script src="../../static/easyui/jquery.cookie.js" type="text/javascript"></script>
<script src="../../static/easyui/ui-theme.js" type="text/javascript"></script>
<script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
<script src="../../ffres/dict/all.js" type="text/javascript"></script>
	<link href="../../static/easyui/themes/frameless.css" rel="stylesheet" type="text/css"/>
	<a href="" target="_blank" id="commonLink" name="commonLink"></a>
</head>
<script type="text/javascript">

	function doAdd(){
		JLEUtil.createModalWin('新增', 'BpaInstInfoAdd.html');
	}
	
	function doUpdate() {
		var row = $('#dg').datagrid('getSelected');
		if (row){
			JLEUtil.createModalWin('修改', 'BpaInstInfoUpdate.html?' + 'bpaId=' + row.bpaId);
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}
	
	function doDelete(){
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			$.messager.confirm('删除提示', '你确定要删除这条记录?', function(r){
				if (r){
					var jsonData = JSON.parse('{'+'"bpaId":"' + row.bpaId + '"'+'}');
					$.restfulDelete('../../api/bat/inst/batch', jsonData, function(data) {
						$.messager.alert('提示','记录删除成功!','info');
						$('#dg').datagrid('reload');
					});
				}
			});
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}

	function doView(){
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			JLEUtil.createModalWin('详情','BpaInstInfoView.html?' + '&bpaId=' + row.bpaId);
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}
	
	function doMonitorBatch(){
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			JLUtil.linkNewPage('BatchMonitor.html?bpaSerialNo='+row.bpaSerialNo+'&bpaId='+row.bpaId);
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}

	function reloadList(){
		$('#dg').datagrid('reload');
		JLEUtil.closewin();
	};
	
	$(function() {
		$('#updateBatBatchToStop').linkbutton('disable');
		$('#updateBatBatchToContinue').linkbutton('disable');
		$('#updateBatBatchToAgen').linkbutton('disable');
		$('#batchToRun').linkbutton('disable');
	});
	
	function buttonDisable(row){
		//var row = $('#dg').datagrid('getSelected');
		if (row.bpaId != null) {
			if (row.bpaInterveneState == 0 && row.bpaState != 9) {
				$('#updateBatBatchToStop').linkbutton('enable');
			} else {
				$('#updateBatBatchToStop').linkbutton('disable');
			}
			
			if (row.bpaState != 9) {
				$('#updateBatBatchToContinue').linkbutton('enable');
			} else {
				$('#updateBatBatchToContinue').linkbutton('disable');
			}
			
			if (row.bpaInterveneState == 1 || row.bpaState == 9) {
				$('#updateBatBatchToAgen').linkbutton('enable');
				$('#batchToRun').linkbutton('enable');
			} else {
				$('#updateBatBatchToAgen').linkbutton('disable');
				$('#batchToRun').linkbutton('disable');
			}
		} else {
			$('#updateBatBatchToStop').linkbutton('disable');
			$('#updateBatBatchToContinue').linkbutton('disable');
			$('#updateBatBatchToAgen').linkbutton('disable');
			$('#batchToRun').linkbutton('disable');
		}
	}
	
	//行选择事件
	function doOnSelect(rowIndex, rowData) {
		if (rowData.bpaInterveneState == 0 && rowData.bpaState != 9) {
			$('#updateBatBatchToStop').linkbutton('enable');
		} else {
			$('#updateBatBatchToStop').linkbutton('disable');
		}
		
		if (rowData.bpaState == 1) {
			$('#updateBatBatchToContinue').linkbutton('enable');
		} else {
			$('#updateBatBatchToContinue').linkbutton('disable');
		}
		
		if (rowData.bpaInterveneState == 1 || rowData.bpaState == 9) {
			$('#updateBatBatchToAgen').linkbutton('enable');
			$('#batchToRun').linkbutton('enable');
		} else {
			$('#updateBatBatchToAgen').linkbutton('disable');
			$('#batchToRun').linkbutton('disable');
		}
	}

	//流程调启
	function doBatchToRun() {

	}

	//流程暂停
	function doUpdateBatBatchToStop() {
		var row = $('#dg').datagrid('getSelected');
		if (row && row.bpaId != null) {
			if (confirm("是否确认要暂停流程？")) {
				var params = {
					bpaId : row.bpaId,
					batchAction : 'stop'
				}
				$.restfulGet('../../api/bat/batch/info/action/', params,
					function(data) {
						if (data.code == '0') {
							$.messager.alert('提示', data.message,'success');
							buttonDisable(row);
						} else {
							$.messager.alert('提示', data.message,'error');
						}
					});
			}
		} else {
			alert('请在查询到的结果集中选择一条记录！');
		}
	}

	//续跑
	function doUpdateBatBatchToContinue() {
		var row = $('#dg').datagrid('getSelected');
		if (row && row.bpaId != null) {
			if (confirm("是否确认要续跑流程？")) {
				var params = {
					bpaSerialNo : row.bpaSerialNo,
					bpaId : row.bpaId,
					batchAction : 'continue'
				}
				$.restfulGet('../../api/bat/bpm/batch/info/action/', params,
					function(data) {
						if (data.code == '0') {
							$.messager.alert('提示', data.message,'success');
							buttonDisable(row);
						} else {
							$.messager.alert('提示', data.message,'error');
						}
					});
			}
		} else {
			alert('请在查询到的结果集中选择一条记录！');
		}
	}
	
	//重跑
	function doUpdateBatBatchToAgen(){
		var row = $('#dg').datagrid('getSelected');
		if (row && row.bpaId != null) {
			if (confirm("是否确认要重跑流程？")) {
				var params = {
					bpaId : row.bpaId,
					batchAction : 'rerun'
				}
				$.restfulGet('../../api/bat/batch/info/action/', params,
					function(data) {
						if (data.code == '0') {
							$.messager.alert('提示', data.message,'success');
							buttonDisable(row);
						} else {
							$.messager.alert('提示', data.message,'error');
						}
					});
			}
		} else {
			alert('请在查询到的结果集中选择一条记录！');
		}
	}
	
	//中断
	function doUpadteBatInstToEnd() {
		var row = $('#dg').datagrid('getSelected');
		if (row && row.bpaId != null) {
			if (confirm("是否确认要中断流程？")) {
				var params = {
					bpaId : row.bpaId,
					batchAction : 'continue'
				}
				$.restfulGet('../../api/bat/inst/end/' + row.bpaId, null,
					function(data) {
						if (data.code == '0') {
							$.messager.alert('提示', data.message,'success');
							buttonDisable(row);
						} else {
							$.messager.alert('提示', data.message,'error');
						}
					});
			}
		} else {
			alert('请在查询到的结果集中选择一条记录！');
		}
	}
</script>
</head>
<body class="easyui-layout">
<div data-options="region:'north',title:''" style="height: 100px; " >
	<form id="searchForm">
		<table>
			<tr>
				<td class="searchTd">业务流水号：</td>
				<td><input name="bpaSerialNo" id="bpaSerialNo"/></td>
				<td class="searchTd">流程标识：</td>
				<td><input name="bpaId" id="bpaId"/></td>
				<td class="searchTd">流程名称：</td>
				<td><input name="bpaName" id="bpaName"/></td>
				<td class="searchTd">流程状态：</td>
				<td class="searchTd"><select name="bpaState" id="bpaState"
							class="easyui-combobox"
							style="width: 100%; height: 25px;"
							data-options="editable:false,valueField:'enname',textField:'cnname',data:BAT_BATCH_STATE"/>
				</td>
			</tr>
			<tr>
				<td class="searchTd">流程日期(起）：</td>
				<td>
					<input class="easyui-datebox" name="bpaDateStart" id="bpaDateStart"
						   data-options="showSeconds: false" style="width:100%"/>
				</td>
				<td class="searchTd"> 流程日期(止）：</td>
				<td><input class="easyui-datebox" name="bpaDateEnd" id="bpaDateEnd"
						   data-options="showSeconds: false" style="width:100%"/></td>
				<td class="searchTd"> 启动时间(起）：</td>
				<td><input class="easyui-datetimebox" name="startTimeStart" id="startTimeStart"
						   data-options="showSeconds: true" style="width:100%"/></td>
				<td class="searchTd"> 启动时间(止）：</td>
				<td><input class="easyui-datetimebox" name="startTimeEnd" id="startTimeEnd"
						   data-options="showSeconds: true" style="width:100%"/></td>
			</tr>
			<tr>
				<td class="searchTd"> 结束时间(起）：</td>
				<td><input class="easyui-datetimebox" name="endTimeStart" id="endTimeStart"
						   data-options="showSeconds: true" style="width:100%"/></td>
				<td class="searchTd"> 结束时间(止）：</td>
				<td><input class="easyui-datetimebox" name="endTimeEnd" id="endTimeEnd"
						   data-options="showSeconds: true" style="width:100%"/></td>

				<td><a class="easyui-linkbutton" href="javascript:void(0);" onclick="JLEUtil.queryForm('searchForm','dg','../../api/bpm/bat/inst/batchs');">查找</a></td>
				<td><a class="easyui-linkbutton" href="javascript:void(0);" onclick="JLEUtil.clearForm('searchForm');">清空</a></td>
			</tr>
		</table>
	</form>
</div>
<div data-options="region:'center',split:false">
<table id="dg" class="easyui-datagrid" title="" style="width:100%;height:93%"
			data-options="singleSelect:true,collapsible:true,url:'../../api/bpm/bat/inst/batchs',method:'post',onSelect: doOnSelect"
			toolbar="#tb"
		title="Load Data" 
		rownumbers="true" pagination="true" pageSize="20">
		<thead>
			<tr>
				<th data-options="field:'bpaSerialNo',resizable:true" >业务流水号</th>
				<th data-options="field:'bpaId',resizable:true" >流程标识</th>
				<th data-options="field:'bpaDate',resizable:true" >流程日期</th>
				<th data-options="field:'bpaName',resizable:true" >流程名称</th>
				<th data-options="field:'subsCode',resizable:true" >所属系统</th>
				<th data-options="field:'bpaState',resizable:true" formatter="formatter_BAT_BATCH_STATE">流程状态</th>
				<th data-options="field:'bpaInterveneState',resizable:true" formatter="formatter_BAT_BATCH_INTERVENE_STATE">人工干预</th>
				<th data-options="field:'stageName',resizable:true" >流程阶段</th>
				<th data-options="field:'startTime',resizable:true" >启动时间</th>
				<th data-options="field:'endTime',resizable:true" >结束时间</th>
				<!-- <th data-options="field:'costTime',resizable:true" >运行时长（秒）</th> -->
			</tr>
		</thead>
	</table>
</div>
<div id="tb" style="padding:1px">
	<div style="margin-bottom:2px">
		<!-- <a href="javascript:doAdd()" class="easyui-linkbutton" iconCls="icon-add" plain="true">新增</a>
		<a href="javascript:doUpdate()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
		<a href="javascript:doDelete()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
		<a href="javascript:doUpdate()" class="easyui-linkbutton" iconCls="icon-ok" plain="true">查看</a> -->
		
		<a href="javascript:void(0)" onclick="doBatchToRun();" id="batchToRun" class="easyui-linkbutton" iconCls="icon-ok" plain="true" style="display:none;">调起</a>
		<a href="javascript:void(0)" onclick="doUpdateBatBatchToStop();" id="updateBatBatchToStop" class="easyui-linkbutton" iconCls="icon-ok" plain="true" style="display:none;">暂停</a>
		<a href="javascript:void(0)" onclick="doUpdateBatBatchToContinue();" id="updateBatBatchToContinue" class="easyui-linkbutton" iconCls="icon-ok" plain="true">续跑</a>
		<a href="javascript:void(0)" onclick="doUpdateBatBatchToAgen();" id="updateBatBatchToAgen" class="easyui-linkbutton" iconCls="icon-ok" plain="true" style="display:none;">重跑</a>
		<a href="javascript:void(0)" onclick="doUpadteBatInstToEnd();" class="easyui-linkbutton" iconCls="icon-ok" plain="true" style="display:none;">中断</a>
		<a href="javascript:void(0)" onclick="doMonitorBatch();" class="easyui-linkbutton" iconCls="icon-ok" plain="true">流程监控</a>
	</div>
</div>
</body>
</html>
